package com.yohann.eduservice.service.impl;

import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yohann.eduservice.entity.EduVideo;
import com.yohann.eduservice.client.VodClient;
import com.yohann.eduservice.mapper.EduVideoMapper;
import com.yohann.eduservice.service.EduVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程视频 服务实现类
 * </p>
 *
 * @author Yohann
 * @since 2020-08-08
 */
@Service
public class EduVideoServiceImpl extends ServiceImpl<EduVideoMapper, EduVideo> implements EduVideoService {
    @Autowired
    private VodClient vodClient;

    /**
     * 删除小节以及视频
     * @param videoQueryWrapper
     */
    @Override
    public void removeVideo(QueryWrapper<EduVideo> videoQueryWrapper) {
        List<EduVideo> videoList = this.list(videoQueryWrapper);
        //获取视频id集合
        List<String> ids = new ArrayList<>();
        for (EduVideo video : videoList) {
            if (!StringUtils.isEmpty(video.getVideoSourceId())){
                ids.add(video.getVideoSourceId());
            }
        }
        //删除视频
        vodClient.deleteBatch(ids);

        //删除数据
        this.remove(videoQueryWrapper);
    }
}